import services from '@/services';
const state = {
  userInfo: {},
  isLogin: false, //当前是否登陆
  refreshAddress: true, //刷新收货地址
  addressList: [], //地址列表
  checkOrderAddress: { //结算单默认地址
    id: "",
    name: "",
    address: "",
    mobile: "",
  },
  collectionList: [], //收藏列表
}
const mutations = {
  //设置收藏列表
  setCollectionList(state, data) {
    state.collectionList = data;
  },
  //设置用户信息
  setUserInfo(state, data) {
    state.userInfo = data;
  },
  setIsLogin(state, data) {
    state.isLogin = data;
  },
  setRefreshAddress(state, data) {
    state.refreshAddress = data;
  },
  setAddressList(state, data) {
    state.addressList = data;
  },
  setCheckOrderAddress(state, data) {
    state.checkOrderAddress = data;
  }
}
const actions = {
  /** 
   * 我的博客
   */
  async myBlog(store, params) {
    const {
      data
    } = await services.user.myBlog(params);
    return data;
  },
  /** 
   * 我的评价
   */
  async myEvaluate(store, params) {
    const {
      data
    } = await services.user.myEvaluate(params);
    return data;
  },
  /** 
   * 我的评论
   */
  async myComments(store, params) {
    const {
      data
    } = await services.user.myComments(params);
    return data;
  },
  /** 
   * 签到
   */
  async signin(store, params) {
    const {
      data
    } = await services.user.signin(params);
    return data;
  },
  /** 
   * 获取会员积分明细
   */
  async accountPointList(store, params) {
    const {
      data
    } = await services.user.accountPointList(params);
    return data;
  },
  /** 
   * 获取会员经验明细
   */
  async accountExpList(store, params) {
    const {
      data
    } = await services.user.accountExpList(params);
    return data;
  },
  /** 
   * 会员列表
   */
  async accountList(store, params) {
    const {
      data
    } = await services.user.accountList(params);
    return data;
  },
  //登陆
  async login(store, params) {
    const {
      data
    } = await services.user.login(params);
    return data;
  },
  //验证码
  async cap(store, params) {
    const {
      data
    } = await services.user.cap(params);
    return data;
  },
  //注册
  async register(store, params) {
    const {
      data
    } = await services.user.register(params);
    return data;
  },
  //发送邮箱验证码
  async sendEmail(store, params) {
    const {
      data
    } = await services.user.sendEmail(params);
    return data;
  },
  //注销登陆
  async logout(store, params) {
    const {
      data
    } = await services.user.logout(params);
    return data;
  },
  //找回密码
  async retpwd(store, params) {
    const {
      data
    } = await services.user.retpwd(params);
    return data;
  },
  //获取用户信息
  async userInfo(store, params) {
    const {
      data
    } = await services.user.userInfo(params);
    return data;
  },
  //修改用户信息
  async updateUserInfo(store, params) {
    const {
      data
    } = await services.user.updateUserInfo(params);
    return data;
  },
  //重置密码
  async resepwd(store, params) {
    const {
      data
    } = await services.user.resepwd(params);
    return data;
  },
  //收货地址
  async address(store, params) {
    const {
      data
    } = await services.user.address(params);
    store.commit('setAddressList', data.data);
    store.commit('setRefreshAddress', false);
    return data;
  },
  //新增收货地址
  async addressAdd(store, params) {
    const {
      data
    } = await services.user.addressAdd(params);
    return data;
  },
  //编辑收货地址
  async addressEdit(store, params) {
    const {
      data
    } = await services.user.addressEdit(params);
    return data;
  },
  //删除收货地址
  async addaddressDelress(store, params) {
    const {
      data
    } = await services.user.addaddressDelress(params);
    return data;
  },
  //收藏列表
  async collectionList(store, params) {
    const {
      data
    } = await services.user.collectionList(params);
    store.commit('setCollectionList', data.data.list); //保存收货地址
    return data;
  },
}
export default {
  namespaced: true,
  state,
  mutations,
  actions
}
